var jRL = null;
var ds = null;
var fields = new Array("username", "password");
function onLoad()
{
	var frm=document.getElementById("jazzila.register.form");
	form = window.arguments[0];
	for (var i=0; i < form.length; i++)
	{
		var item = form.item(i);
		if (item.nodeType == item.TEXT_NODE)
			continue;
		var txt = document.getElementById("jazzila.register."+item.nodeName);
		if (!txt) 
		{
			var lbl = document.createElement("label");
			lbl.setAttribute("value", item.nodeName);
			var row=document.createElement("row");
			row.appendChild(lbl);
			frm.appendChild(row);
			txt = document.createElement("textbox");
			txt.setAttribute("id", "jazzila.register."+item.nodeName);
			row.appendChild(txt);
		}
		if (item.childNodes.length)
				txt.setAttribute("value", item.firstChild.nodeValue);
		if (item.nodeName =="instructions")
			continue;
		fields.push(item.nodeName);
	}
	var pass2 = document.getElementById("jazzila.register.password2");
	var pass  = document.getElementById("jazzila.register.password");
	if (pass2)
	{
		pass2.value = pass.value;
	}
}

function onUnload()
{
}

Jazzila.prototype.doRegister = function ()
{
   var pass1 = document.getElementById("jazzila.register.password");
   var pass2 = document.getElementById("jazzila.register.password2");
   var doc = CC["@mozilla.org/xml/xml-document;1"].createInstance();
   var form = doc.createElement("form");
   if(pass1.value != pass2.value )
   {
		alert("passwords do not match "+pass1.value + " : " +pass2.value);
		return false;
   }
   for (var i in fields)
   {
	 var tag=fields[i];
	 var txt = document.getElementById("jazzila.register."+tag).value
	 if ( txt == "")
		 return false;
     	 var node = doc.createElement(tag);
	 node.appendChild(doc.createTextNode(txt));
	 form.appendChild(node);
   }
   return this.nsIXmppService.registerIn(form.childNodes);
}

Jazzila.prototype.doCancel = function ()
{
	window.close();
	this.nsIXmppService.disconnect();
}

window.addEventListener("load", onLoad, false);
window.addEventListener("unload", onUnload, false);
